﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace TfsUtils.Utils
{
    public static class ExpressionExtensions
    {
        public static String GetMemberName<T>(this Expression<Func<T>> source)
        {
            var expression = source.Body as MemberExpression;
            if (expression != null)
            {
                var member = expression.Member;
                return member.Name;
            }

            throw new NotSupportedException("Only MemberExpression(s) are supported.");
        }

        public static String GetMemberName<T, TProperty>(this Expression<Func<T, TProperty>> source)
        {
            var expression = source.Body as MemberExpression;
            if (expression != null)
            {
                var member = expression.Member;
                return member.Name;
            }

            throw new NotSupportedException("Only MemberExpression(s) are supported.");
        }
    }
}
